/*This file runs the NAICS 6-digit results in Table O8 of online appendix
Some of the regressions take a considerable time to run*/    
**Curtis RESTAT
**Change to directory where data and code were downloaded
**cd 
 *pause on
    set more off
    clear all
    *set mem 1G
    *#delimit 


*log using regs6int.log, replace

set matsize 11000
set maxvar 11000
use stind6_17_tableO8,clear
gen naics1=substr(naics,1,1)
keep if naics1=="3"
do dataclean_tableO8.do

destring year,replace
gen trend=year-1997
drop if year>2009
tostring year,replace
qui tab year,gen(yeardum)
gen styear=fipstate+year
cap qui tab styear,gen(STyeardum)
gen empweight2=emp if year=="1998"
replace empweight2=emp
bysort stateind:carryforward empweight2,replace

so naics
merge m:1 naics using "eite_ind_tableO8.dta"
replace eite_ind=0 if eite_ind==.
gen postxeastxeite=postxeast*eite_ind
gen postxeite=post*eite_ind
gen eitexeast=east*eite_ind
tostring east,gen(eaststr)
tostring eite_ind,gen(eitestr)
gen easteite=eaststr+eitestr
gen naicseite=naics+eitestr
gen eastind=eaststr+naics

foreach y of varlist ind* {
qui gen indtrend`y' = `y'*trend
 }

foreach y of varlist ind* {
qui gen eindtrend`y' = `y'*east*trend
 }
 
foreach y of varlist ind* {
qui gen windtrend`y' = `y'*((east-1)^2)*trend
 }
 
 foreach y of varlist STdum* {
qui gen STtrend`y' = `y'*trend
 }




eststo clear

eststo: qui areg lemp  postxeastxint postxint intxeast postxeast yeardum*[aweight=empweight2] ,abs(STind) rob cluster(eastind)
eststo: qui areg lemp  postxeastxint postxint intxeast postxeast STyeardum* [aweight=empweight2],abs(STind) rob cluster (eastind)
eststo: qui xi: areg lemp  postxeastxint postxint intxeast postxeast i.yearind STtrend* [aweight=empweight2],abs(STind) rob cluster (eastind)
esttab using "TableO8a.tex",se replace  title(Six Digit Industry) keep(postxeastxint postxeast) star(* 0.10 ** 0.05 *** 0.01) 

drop STdum* STyeardum* yeardum* ind*


eststo: qui areg lemp  postxeastxint postxint intxeast postxeast yeardum* windtrendind* eindtrendind*[aweight=empweight2] ,abs(STind) rob cluster(eastind)
eststo: qui areg lemp  postxeastxint postxint intxeast postxeast STyeardum* windtrendind* eindtrendind* [aweight=empweight2],abs(STind) rob cluster (eastind)
eststo: qui xi: areg lemp  postxeastxint postxint intxeast postxeast i.yearind STtrend* windtrendind* eindtrendind* [aweight=empweight2],abs(STind) rob cluster (eastind)

esttab using "TableO8ab.tex",se replace  title(Six Digit Industry) keep(postxeastxint postxeast) star(* 0.10 ** 0.05 *** 0.01) 


